06. How to Use Accumulators

What are Accumulators?

As the name hints, accumulators are variables that accumulate. Because Spark runs in distributed mode, the workers are running in parallel, but asynchronously. For example, worker 1 will not be able to know how far worker 2 and worker 3 are done with their tasks. With the same analogy, the variables that are local to workers are not going to be shared to another worker unless you accumulate them. Accumulators are used for mostly sum operations, like in Hadoop MapReduce, but you can implement it to do otherwise.

For additional deep-dive, here is the Spark documentation on accumulators if you want to learn more about these.

Spark L3 SC 21 How To Use Accumulators

What would be the best scenario case to use Spark Accumulators?

What would be the best scenario for using Spark Accumulators?

SOLUTION: When you know you will have different values across your executors